/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MathLib.Geometry;

import java.io.BufferedOutputStream;
import java.io.PrintWriter;

/**
 *
 * @author marko
 */
public class Square implements IFigure {
    public String Name="";
    protected Point2DDouble A;
    protected double a;

    public Square(){

    }

    public Square(Point2DDouble A,double a){
        this.A = A;
        this.a = a;
    }

    public double Ax(){return A.x;}
    public double Ay(){return A.y;}
    public Point2DDouble A(){
        return new Point2DDouble(A.x, A.y);
    }

    public double Bx(){return A.x+a;}
    public double By(){return A.y;}
    public Point2DDouble B(){
        return new Point2DDouble(A.x+a, A.y);
    }

    public double Cx(){return A.x+a;}
    public double Cy(){return A.y-a;}
    public Point2DDouble C(){
        return new Point2DDouble(A.x+a, A.y-a);
    }

    public double Dx(){return A.x;}
    public double Dy(){return A.y-a;}
    public Point2DDouble D(){
        return new Point2DDouble(A.x, A.y - a);
    }

    public boolean Include(Point2DDouble x){
        return ( (x.x>=A.x)&&(x.x<=A.x+a)&&(x.y>=A.y)&&(x.y<=A.y+a) );
    }
    public void printToFile(BufferedOutputStream out) {
        PrintWriter o = new PrintWriter(out);
        o.println("4 2 0 0");
        o.println(1+" "+this.A.x+" "+this.A.y);
        o.println(2+" "+this.Bx()+" "+this.By());
        o.println(3+" "+this.Cx()+" "+this.Cy());
        o.println(4+" "+this.Dx()+" "+this.Dy());
        o.println("4 0");
        o.println("1 1 2");
        o.println("2 2 3");
        o.println("3 3 4");
        o.println("4 4 1");
        o.println("0");
        o.close();
    }
    public double getLength(){return a;}

    public void printToFileQuad(BufferedOutputStream out) {
        PrintWriter o = new PrintWriter(out);
        o.println("4");
        o.println(this.A.x+" "+this.A.y + " 2");
        o.println(this.Bx()+" "+this.By() + " 2");
        o.println(this.Cx()+" "+this.Cy() + " 2");
        o.println(this.Dx()+" "+this.Dy() + " 2");
        o.println("0\n 1");
        o.println("4 0 0");
        o.println("1 2 3 4");
        o.println("2 2 2 2");
        o.close();
    }
}
